/* Copyright (c) 2009-2010, Sean A.O. Harney <sharney3@gmail.com> */

#include "omf.h"


//expects already evaled leaf expr of INT
// returns NULL, later will return perhgaps if fsync worked or not instead of fatal.
EXPR_P builtin_func_flush(EXPR_P expr)
{
    if (expr->u.leaf.type != LEAF_INT)
	fatal_error_println
	    ("OMF built-in function flush() expects INT expr as argument.");


    INTVAL_P iv = expr->u.leaf.val.int_val;	//TODO: move to util func to check if positive also as in sleep.c
    int fd = iv->ulong_val;

    if (fsync(fd) < 0)
	fatal_error_perror("fsync()");	// NOTE: should be fatal or perhaps just return -1 so as not to end calling program?? FIXME

    debug1_printf("flushed fileno %d.\n", fd);

    return NULL;
}
